package com.ktgj.pay.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.pay.domain.InvoiceInvoiceOrderDTO;
import com.ktgj.pay.domain.vo.InvoiceInvoiceOrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.pay.domain.InvoiceInvoiceOrder;
import com.ktgj.pay.service.IInvoiceInvoiceOrderService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 发票订单Controller
 * 
 * @author ruoyi
 * @date 2022-01-24
 */
@RestController
@RequestMapping("/invoiceOrder")
public class InvoiceInvoiceOrderController extends BaseController
{
    @Autowired
    private IInvoiceInvoiceOrderService invoiceInvoiceOrderService;

    /**
     * 查询发票订单列表
     */
    //@PreAuthorize(hasPermi = "invoice:order:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody InvoiceInvoiceOrder invoiceInvoiceOrder)
    {
        startPage();
        List<InvoiceInvoiceOrder> list = invoiceInvoiceOrderService.selectInvoiceInvoiceOrderList(invoiceInvoiceOrder);
        return getDataTable(list);
    }

    /**
     * 导出发票订单列表
     */
    //@PreAuthorize(hasPermi = "invoice:order:export")
    @Log(title = "发票订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvoiceInvoiceOrder invoiceInvoiceOrder) throws IOException
    {
        List<InvoiceInvoiceOrder> list = invoiceInvoiceOrderService.selectInvoiceInvoiceOrderList(invoiceInvoiceOrder);
        ExcelUtil<InvoiceInvoiceOrder> util = new ExcelUtil<InvoiceInvoiceOrder>(InvoiceInvoiceOrder.class);
        util.exportExcel(response, list, "发票订单数据");
    }

    /**
     * 获取发票订单详细信息
     */
    //@PreAuthorize(hasPermi = "invoice:order:query")
    @PostMapping("/getInfo")
    public AjaxResult getInfo(@RequestBody Map<String, Object> map)
    {
        Long invoiceid = Long.valueOf(map.get("invoiceid").toString());
        return AjaxResult.success(invoiceInvoiceOrderService.selectInvoiceInvoiceOrderById(invoiceid));
    }
    /**
     * 会员发票订单列表（CRM）
     * */
    @PostMapping("/getListByCustomerId")
    public List<InvoiceInvoiceOrder> getListByCustomerId(@RequestBody String jsjid)
    {
       List<InvoiceInvoiceOrder> invoiceInvoiceOrder= invoiceInvoiceOrderService.selectInvoiceInvoiceOrderListByCustomerId(jsjid);
        return invoiceInvoiceOrder;
    }

    /**
     * 新增发票订单
     */
    //@PreAuthorize(hasPermi = "invoice:order:add")
    @Log(title = "发票订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody InvoiceInvoiceOrder invoiceInvoiceOrder)
    {
        int i = invoiceInvoiceOrderService.insertInvoiceInvoiceOrder(invoiceInvoiceOrder);
        if (i > 0){
            return AjaxResult.success("新增成功");
        }
        else {
            return AjaxResult.error("新增失败");
        }
    }

    /**
     * 修改发票订单
     */
    //@PreAuthorize(hasPermi = "invoice:order:edit")
    @Log(title = "发票订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody InvoiceInvoiceOrder invoiceInvoiceOrder)
    {
        return toAjax(invoiceInvoiceOrderService.updateInvoiceInvoiceOrder(invoiceInvoiceOrder));
    }

    /**
     * 删除发票订单
     * @param map
     * @return
     */
    @PostMapping("/deleteInvoiceInvoiceOrderById")
    public AjaxResult deleteInvoiceInvoiceOrderById(@RequestBody Map<String, Object> map) {
        Long invoiceid = Long.valueOf(map.get("invoiceid").toString());
        return toAjax(invoiceInvoiceOrderService.deleteInvoiceInvoiceOrderById(invoiceid));
    }

    /**
     * 删除发票订单
     */
    //@PreAuthorize(hasPermi = "invoice:order:remove")
    @Log(title = "发票订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{invoiceids}")
    public AjaxResult remove(@PathVariable Long[] invoiceids)
    {
        return toAjax(invoiceInvoiceOrderService.deleteInvoiceInvoiceOrderByIds(invoiceids));
    }

    /**
     * 发票查询
     * @param invoiceOrder
     * @return
     */
    @PostMapping("/invoiceOrderList")
    public TableDataInfo invoiceOrderList(@RequestBody InvoiceInvoiceOrderVO invoiceOrder) {
        startPage();
        List<InvoiceInvoiceOrderDTO> invoiceOrderDTOS = invoiceInvoiceOrderService.invoiceOrderList(invoiceOrder);
        return getDataTable(invoiceOrderDTOS);
    }
}
